package com.heyqing.medium.day7;

/**
 * ClassName:FindComplement
 * Package:com.heyqing.medium.day7
 * Description:
 *
 * @Date:2024/10/9
 * @Author:Heyqing
 */
public class FindComplement {
    public int findComplement(int num) {
        String b = Integer.toBinaryString(num);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < b.length(); i++) {
            sb.append(b.charAt(i) == '1' ? '0' : '1');
        }
        return Integer.parseInt(sb.toString(), 2);
    }
    //~num & ((Integer.highestOneBit(num) << 1) - 1);
}
